<template>
	<view class="orderInfo-wrap" v-if="commodityOrder">
		<view class="orderInfo-price-mod">
			<u-title value="付款详情"></u-title>
			<view class="orderInfo-price-num">
				<view class="word3">{{ orderTypeList[commodityOrder.orderType].name }}-{{ inquiryTypeList[commodityOrder.inquiryType].name }}</view>
				<!-- <view class="txt1">¥&nbsp;{{ commodityOrder.totalAmount }}</view> -->
				<!-- 待支付 -->
				<view class="info2 info2-red" v-if="commodityOrder.status == 3">{{ orderStatusList[commodityOrder.status] }}</view>
				<!-- 待接诊 -->
				<view class="info2 info2-red" v-else-if="commodityOrder.status == 1 && questionOrder.status == 0">{{ qStatusList[questionOrder.status] }}</view>
				<!-- 问诊中 -->
				<view class="info2 info2-green" v-else-if="questionOrder.status == 1">{{ qStatusList[questionOrder.status] }}</view>
				<!-- 已开处方 -->
				<view class="info2 info2-green" v-else-if="questionOrder.status == 2">{{ qStatusList[questionOrder.status] }}</view>
				<!-- 已退诊 -->
				<view class="info2 info2-gray" v-else-if="questionOrder.status == 4">{{ qStatusList[questionOrder.status] }}</view>
				<!-- 退款中|已退款 -->
				<view class="info2 info2-gray" v-else-if="commodityOrder.status == 4 || commodityOrder.status == 5">{{ orderStatusList[commodityOrder.status] }}</view>
				<!-- 待发货|待收货 -->
				<view class="info2 info2-purple" v-else-if="commodityOrder.status == 7 || commodityOrder.status == 8">{{ orderStatusList[commodityOrder.status] }}</view>
				<!-- 已完成 -->
				<view class="info2 info2-gray" v-else-if="commodityOrder.status == 1 || questionOrder.status == 3">{{ qStatusList[questionOrder.status] }}</view>
				<!-- 其他状态 -->
				<view class="info2 info2-purple" v-else>{{ orderStatusList[commodityOrder.status] }}</view>
			</view>

			<view class="orderInfo-price-num" v-if="questionOrder.subTime">
				<view class="word3">预约时间</view>
				<view class="txt1">{{ questionOrder.subTime }}</view>
			</view>
		</view>

		<view class="orderInfo-drug" v-if="commodityOrder.orderType == 2 && questionOrder.drugQuestionReq">
			<u-title value="已选药品"></u-title>
			<view class="orderInfo-drug-list"><u-show-goods v-for="(item, index) in questionOrder.drugQuestionReq.commodityList" :key="index" :data="item"></u-show-goods></view>
		</view>

		<view class="orderInfo-patient">
			<u-title value="问诊信息"></u-title>
			<view class="orderInfo-patient-box">
				<view class="orderInfo-patient-outer">
					<text lines="1" class="word9">患者信息：</text>
					<text lines="1" class="word10">{{ patient.patientName }}&nbsp;&nbsp;{{ rangeSex[patient.sex].text }}&nbsp;&nbsp;{{ patient.phone }}</text>
				</view>
				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType == 2">
					<text lines="1" class="word9">所患疾病：</text>
					<text lines="1" class="word10">{{ questionOrder.content }}</text>
				</view>

				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType == 2">
					<text lines="1" class="word9">肝功能：</text>
					<text lines="1" class="word10">{{ functionList[questionOrder.drugQuestionReq.liver].name }}</text>
				</view>

				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType == 2">
					<text lines="1" class="word9">肾功能：</text>
					<text lines="1" class="word10">{{ functionList[questionOrder.drugQuestionReq.kidney].name }}</text>
				</view>

				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType == 2 && questionOrder.drugQuestionReq.allergy == 1">
					<text lines="1" class="word9">过敏史：</text>
					<text lines="1" class="word10">{{ questionOrder.drugQuestionReq.allergyText }}</text>
				</view>

				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType == 2">
					<text lines="1" class="word9">生育状态及计划：</text>
					<text lines="1" class="word10">{{ birthStatusList[questionOrder.drugQuestionReq.birthStatus].name }}</text>
				</view>

				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType != 2">
					<text lines="1" class="word9">患病时间：</text>
					<text lines="1" class="word10">{{ durationList[questionOrder.duration].name }}</text>
				</view>
				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType != 2">
					<text lines="1" class="word9">就诊情况：</text>
					<text lines="1" class="word10">{{ isLookHospList[questionOrder.isLookHosp].name }}</text>
				</view>
				<view class="orderInfo-patient-outer" v-if="commodityOrder.orderType != 2">
					<text lines="1" class="word9">病情描述：</text>
					<text lines="1" class="word10">{{ questionOrder.content }}</text>
				</view>
			</view>
		</view>

		<view class="orderInfo-report" v-if="reportList.length > 0">
			<u-title value="处方证明"></u-title>
			<view class="orderInfo-report-list" ><image :src="item" class="orderInfo-report-item" v-for="(item, index) in reportList" :key="index" @click="previewImage(reportList,index)"></image></view>
		</view>
		
		<view class="orderInfo-report" v-if="questionOrder.reexamination">
			<u-title value="复诊文件（PDF格式文件）"></u-title>
			<view class="orderInfo-report-list" >{{questionOrder.reexamination.split('/').pop()}}</view>
		</view>

		<view class="orderInfo-patient">
			<u-title value="订单信息"></u-title>
			<view class="orderInfo-patient-box">
				<view class="orderInfo-patient-outer">
					<text lines="1" class="word10">订单编号：{{ commodityOrder.outTradeNo }}</text>
					<view class="word-btn" @click="setClipboardData(commodityOrder.outTradeNo)">复制</view>
				</view>
				<view class="orderInfo-patient-outer">
					<text lines="1" class="word10">下单时间：{{ commodityOrder.orderTime }}</text>
				</view>
				<view class="orderInfo-patient-outer">
					<text lines="1" class="word10">订单金额：{{ commodityOrder.totalAmount || 0.00 }} 元</text>
				</view>
				<view class="orderInfo-patient-outer">
					<text lines="1" class="word10">优惠金额：{{ commodityOrder.couponMoney || 0.00 }} 元</text>
				</view>
				<view class="orderInfo-patient-outer">
					<text lines="1" class="word10">支付金额：{{ commodityOrder.orderAmount || 0.00 }} 元</text>
				</view>
			</view>
		</view>

		<u-bottom-button
			type="2"
			value1="退 诊"
			value2="接 诊"
			@clickOne="clinicalReception(4)"
			@clickTwo="clinicalReception(1)"
			v-if="questionOrder.status == 0"
		></u-bottom-button>
		<!--
		<u-bottom-button
			type="3"
			value2="继续问诊"
			@clickTwo="gotoRouter('/pages-im/chatRoom/chatRoom?accid=' + questionOrder.userId + '&role=1')"
			v-if="commodityOrder.status == 1 && questionOrder.status == 1 "
		></u-bottom-button>
		-->
		<u-bottom-button
			type="3"
			value2="继续问诊"
			@clickTwo="continueInquery"
			v-if="commodityOrder.status == 1 && (questionOrder.status == 1 || questionOrder.status == 2)"
		></u-bottom-button>
	</view>
</template>

<script>
import uTitle from '@/components/u-title/u-title.vue';
import uShowGoods from '@/components/u-show-goods/u-show-goods.vue';
import uBottomButton from '@/components/u-bottom-button/u-bottom-button.vue';
import uDoctorItem from '@/components/u-doctor-item/u-doctor-item.vue';
import { currentImInfo } from '@/utils/token.js'
const app = getApp();
export default {
	components: {
		uBottomButton,
		uTitle,
		uDoctorItem,
		uShowGoods
	},
	data() {
		return {
			id: null, //问诊订单id
			patient: null, //患者
			commodityOrder: null, //订单信息
			questionOrder: null, //问诊详情
			reportList: []
		};
	},

	onLoad(option) {
		this.id = option.id;
		this.questionOrderDetail();
	},
	onShow() {},
	methods: {
		//订单详情
		questionOrderDetail() {
			this.$api
				.questionOrderDetail({
					params: {
						id: this.id
					}
				})
				.then(res => {
					if (res.code == 200) {
						if (res.result) {
							this.commodityOrder = res.result.commodityOrder;
							this.patient = res.result.patient;
							this.questionOrder = res.result.questionOrder;
							this.reportList = res.result.questionOrder.reportList;
						}
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//接诊-退诊
		clinicalReception(status) {
			let message = status == 1 ? '接诊' : '退诊';
			uni.showModal({
				title: `确认要${message}吗？`,
				success: res => {
					if (res.confirm) {
						this.$api
							.clinicalReception({
								params: {
									id: this.id,
									status
								}
							})
							.then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: message + '成功',
										icon: 'none'
									});
									if (status == 1) {
										this.gotoChatRoom(this.commodityOrder.userId);
									} else {
										this.questionOrderDetail();
									}
								} else {
									uni.showToast({
										title: res.message,
										icon: 'none'
									});
								}
							});
					}
				}
			});
		},

		//首次进入聊天室
		gotoChatRoom(accid) {
			/*
			getApp().globalData.nim.addFriend({
				account: accid,
				ps: '',
				done: (err, obj) => {
					if (err) {
						console.log(err);
						uni.showToast({
							title: '发起聊天失败',
							icon: 'none'
						});

						return;
					} else {
						this.$store.dispatch('im/CurrentChatTo_Change', {
							session: 'p2p-' + accid,
							account: accid
						});
						uni.reLaunch({
							url: `/pages-im/chatRoom/chatRoom?accid=${accid}&role=1&questionOrderId=${this.questionOrder.id}`
						});
					}
				}
			});
			*/
			this.$store.dispatch('txyIm/CurrentChatTo_Change', {
				session: 'C2C' + accid,
				account: accid
			});
			uni.reLaunch({
				url: `/pages-txy-im/chatRoom/chatRoom?accid=${accid}&role=1&questionOrderId=${this.questionOrder.id}`
			})
		},
		continueInquery() {
			// gotoRouter('/pages-txy-im/chatRoom/chatRoom?accid=' + questionOrder.userId + '&role=1')
			uni.navigateTo({
				url: `/pages-txy-im/chatRoom/chatRoom?accid=${this.questionOrder.userId}&role=1&questionOrderId=${this.questionOrder.id}`
			})
		}
	}
};
</script>

<style lang="less">
@import './orderInfo.less';
</style>
